﻿<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:AdventureWorksLT.Views.Customers.ViewModels" 
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:E2C="clr-namespace:AdventureWorksLT.Core"
xmlns:appControls="clr-namespace:AdventureWorksLT.Controls"
x:Class="AdventureWorksLT.Views.Customers.Controls.SalesOrderDetailGrid"
mc:Ignorable="d"
d:DesignWidth="840" d:DesignHeight="480"
>
    <UserControl.Resources>
        <viewModels:SalesOrderDetailsViewModel x:Key="SalesOrderDetailsViewModel" />
    </UserControl.Resources>
        <appControls:BusyIndicator x:Name="BusyIndicator" BusyContent="Loading SalesOrderDetails data...." DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}" FontSize="18" IsBusy="{Binding IsBusy}">
        <ScrollViewer x:Name="scrollViewerSalesOrderDetail" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" >
    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}"  >



<sdk:DataGrid Width="Auto" Style="{StaticResource DataGridCellJetPackStyle}" CellStyle="{StaticResource LeftCell}" ColumnHeaderStyle="{StaticResource DataGridColumnHeader}" RowHeaderStyle="{StaticResource DataGridRowHeader}" RowStyle="{StaticResource DataGridRow}" AutoGenerateColumns="False" IsReadOnly="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}" ItemsSource="{Binding SalesOrderDetailsCollection, Mode=TwoWay}" x:Name="SalesOrderDetailsDataGrid" >
 <i:Interaction.Triggers>
 <i:EventTrigger EventName="SelectionChanged">
 <E2C:EventToCommand Command="{Binding SelectionChangedSdkCommand}" CommandParameter="{Binding SelectedItem, ElementName=SalesOrderDetailsDataGrid}" ></E2C:EventToCommand>
 </i:EventTrigger>
 <i:EventTrigger EventName="LoadingRow">
 <E2C:EventToCommand Command="{Binding RowLoadingSdkCommand}" PassEventArgsToCommand="True" ></E2C:EventToCommand>
 </i:EventTrigger>
 </i:Interaction.Triggers>
  
                    <sdk:DataGrid.Columns >
        <sdk:DataGridTemplateColumn x:Name="addRow" Width="20">
            <sdk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
     <Button Content="+" Foreground="Black" ToolTipService.ToolTip="Add new Row" DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
<E2C:EventToCommand  Command="{Binding AddNewSalesOrderDetailsCommand}" CommandParameter="{Binding SelectedItem, ElementName=SalesOrderDetailsDataGrid}" ></E2C:EventToCommand>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellTemplate>
        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn x:Name="deleteRow" Width="20">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="-" ToolTipService.ToolTip="Delete Current Row" DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}" >
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <E2C:EventToCommand  Command="{Binding DeleteSalesOrderDetailsCommand}" CommandParameter="{Binding SelectedItem, ElementName=SalesOrderDetailsDataGrid}" ></E2C:EventToCommand>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </Button>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn x:Name="ModifyRow" Width="20">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="..." ToolTipService.ToolTip="Modify Current Row" DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}" >
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <E2C:EventToCommand  Command="{Binding EditCurrentInNewWindowCommand}" CommandParameter="{Binding SelectedItem, ElementName=SalesOrderDetailsDataGrid}" ></E2C:EventToCommand>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </Button>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
     
                        <!--<sdk:DataGridTemplateColumn x:Name="PruductIdComboBox0" Width="150">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <ComboBox Height="26" Margin="2" x:Name="ProductIDComboBox" DataContext="{Binding Source={StaticResource SalesOrderDetailsViewModel}}" ItemsSource="{Binding ProductCollection, Mode=TwoWay}" DisplayMemberPath = "Name" SelectedItem="{Binding SelectedProduct, Mode=TwoWay}" VerticalAlignment="Top" Width="150" >
                                    <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <E2C:EventToCommand  Command="{Binding EditCurrentInNewWindowCommand}" CommandParameter="{Binding SelectedItem, ElementName=SalesOrderDetailsDataGrid}" ></E2C:EventToCommand>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </ComboBox>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>-->
     

                        <sdk:DataGridTextColumn x:Name="SalesOrderIDColumn" Binding="{Binding Path=SalesOrderID}" Header="SalesOrderID" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="idColumn" Binding="{Binding Path=SalesOrderDetailID}" Header="Sales Order Detail Id" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="ProductColumn" Binding="{Binding SelectedProduct.ProductID}" Header="Pruduct ID" Width="SizeToHeader" />
                        <sdk:DataGridTextColumn x:Name="OrderQtyColumn" Binding="{Binding Path=OrderQty}" Header="Order Qty" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="UnitPriceColumn" Binding="{Binding Path=UnitPrice}" Header="Unit Price" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="UnitPriceDiscountColumn" Binding="{Binding Path=UnitPriceDiscount}" Header="Unit Price Discount" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="LineTotalColumn" Binding="{Binding Path=LineTotal}" Header="Line Total" Width="SizeToHeader" />
</sdk:DataGrid.Columns>
                             </sdk:DataGrid>


    </Grid>
  </ScrollViewer>
 </appControls:BusyIndicator>
</UserControl>

